<?php

// $Id$

require_once($WSC->get_site_inc_dir().'modules/tangra_cms/_sys/tcms_admin_page_w_grid_ua.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/grids/images/images_grid_ctrl.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/settings/tcms_settings_images_dbc.class.php');

class Images_WP extends TCMS_Admin_Page_W_Grid_UA {
	public function create_view($name = 'default') {
		$ret = new TCMS_Admin_Page_View($this, $name, 'modules/tangra_cms/pages/_image/');

		return $ret;
	}


	public function init() {
		parent::init();

		$dbc = $this->get_dbc();

		$settings_images = new TCMS_Settings_Images_DBC();
		$settings_images->load_by_id($dbc, 1);
		$this->export('t1_width', $settings_images->get_thumbnail1_size_x());
		$this->export('t1_height', $settings_images->get_thumbnail1_size_y());
		$this->export('t2_width', $settings_images->get_thumbnail2_size_x());
		$this->export('t2_height', $settings_images->get_thumbnail2_size_y());
	}


	 protected function create_grid_ctrl() {
	 	$tvm = $this->get_tvm();

		if (!$tvm->is_page_var_registered('ci_image', 'filename')) {
			$tvm->register_page_var('ci_image', 'filename');
			$tvm->register_page_var('ci_image', 'notealt');
		}
		$this->process_filter($tvm);


		$ret = new Images_Grid_Ctrl('images', $tvm, Tangra_Parameter_Method::GET);

		return $ret;
	 }


	private function process_filter($vm) {
		$context = $this->get__context();
		if ($context->exists_in_get('filename')) {
			$filename = $context->get_from_get('filename');
			$vm->set_page_var('ci_image', 'filename', $filename);
		}
		$filename = $vm->get_page_var('ci_image', 'filename');
		$this->export('filename', $filename);


		if ($context->exists_in_get('notealt')) {
			$notealt = $context->get_from_get('notealt');
			$vm->set_page_var('ci_image', 'notealt', $notealt);
		}
		$notealt = $vm->get_page_var('ci_image', 'notealt');
		$this->export('notealt', $notealt);
	}
}